<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>EDS API: LiveClient.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">EDS API
   </div>
   <div id="projectbrief">Enterprise Data Server Application Programming Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_live_client_8cpp-example.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">LiveClient.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &lt;windows.h&gt;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#include &lt;math.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;time.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// EDS LiveClient header file</span></div>
<div class="line"><span class="preprocessor">#include &quot;../include/LiveClient.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// Some common types are defined in eds namespace</span></div>
<div class="line"><span class="keyword">using namespace </span>eds;</div>
<div class="line"><span class="comment">// LiveClient is in eds::live namespace</span></div>
<div class="line"><span class="keyword">using namespace </span>eds::live;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">namespace </span>utils</div>
<div class="line">{</div>
<div class="line"></div>
<div class="line">  <span class="keywordtype">void</span> sleep(<span class="keywordtype">float</span> seconds)</div>
<div class="line">  {</div>
<div class="line"><span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><span class="preprocessor"></span>    DWORD t;</div>
<div class="line"></div>
<div class="line">    t = (DWORD)(seconds * 1000.0);</div>
<div class="line">    Sleep(t);</div>
<div class="line"><span class="preprocessor">#else</span></div>
<div class="line"><span class="preprocessor"></span>    <span class="keyword">struct </span>timespec t;</div>
<div class="line"></div>
<div class="line">    t.tv_sec = (time_t)floor(seconds);</div>
<div class="line">    t.tv_nsec = (long)((seconds - floor(seconds)) * 1000000000.0);</div>
<div class="line">    nanosleep(&amp;t, NULL);</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span>  }</div>
<div class="line"></div>
<div class="line">  <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line">  T random(T min, T max)</div>
<div class="line">  {</div>
<div class="line">    <span class="keywordtype">double</span> x = <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(rand()) / RAND_MAX;</div>
<div class="line">    T range = max - min;</div>
<div class="line">    <span class="keywordflow">return</span> min + <span class="keyword">static_cast&lt;</span>T<span class="keyword">&gt;</span>(x * range);</div>
<div class="line">  }</div>
<div class="line">} <span class="comment">// namespace utils</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><a name="_a0"></a><a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* initializeClient(<span class="keyword">const</span> <span class="keywordtype">char</span>* version,</div>
<div class="line">                             <span class="keyword">const</span> <span class="keywordtype">char</span>* host,</div>
<div class="line">                             <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> port)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Creating LiveClient for EDS version %s...\n&quot;</span>, version);</div>
<div class="line">    std::auto_ptr&lt;LiveClient&gt; client(<span class="keyword">new</span> <a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>(version));</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Initialize in bidirectional (read-write) mode</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;Initializing LiveClient connection to %s:%u...\n&quot;</span>, host, port);</div>
<div class="line">    client-&gt;init(AccessMode_ReadWrite,</div>
<div class="line">                 <span class="stringliteral">&quot;0.0.0.0&quot;</span>,             <span class="comment">// bind to all local interfaces</span></div>
<div class="line">                 0,                     <span class="comment">// bind to any local port</span></div>
<div class="line">                 host,</div>
<div class="line">                 port,</div>
<div class="line">                 50);</div>
<div class="line"></div>
<div class="line">    printf(<span class="stringliteral">&quot;LiveClient initialized successfully!\n&quot;</span>);</div>
<div class="line">    <span class="keywordflow">return</span> client.release();</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a1"></a><a class="code" href="classeds_1_1_backend_not_found_error.html" title="Backend not found exception class.">BackendNotFoundError</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Couldn&#39;t load backend. Requested version might be incorrect,</span></div>
<div class="line">    <span class="comment">// or &#39;edsapi_live_*&#39; library might be missing.</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;Couldn&#39;t load backend library for EDS %s (%s)\n&quot;</span>,</div>
<div class="line">      version, exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a2"></a><a class="code" href="classeds_1_1live_1_1_live_client_error.html" title="Thrown when backend library returns an error.">LiveClientError</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Couldn&#39;t initialize client connection object (%s)\n&quot;</span>,</div>
<div class="line">      exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">bool</span> subscribePoint(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client, <span class="keyword">const</span> <span class="keywordtype">char</span>* pointName)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Get lid (local id) of point by it&#39;s IESS</span></div>
<div class="line">    <span class="keywordtype">int</span> lid = client-&gt;<a name="a3"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#abcc332d091d41c17046a6fb6c0f5d117" title="Returns local id of point identified by IESS.">findByIESS</a>(pointName);</div>
<div class="line">    <span class="keywordflow">if</span> (lid == -1)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;Couldn&#39;t find point with IESS &#39;%s&#39;\n&quot;</span>, pointName);</div>
<div class="line">      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    client-&gt;<a name="a4"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#ab7ee847fd40c4f16cf4e4aac5a64b4f0" title="Registers LiveClient as receiver of dynamic values for given point.">setInput</a>(lid);</div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a5"></a><a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to subscribe point &#39;%s&#39; (%s)\n&quot;</span>, pointName, exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">bool</span> originatePoint(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client, <span class="keyword">const</span> <span class="keywordtype">char</span>* pointName)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Get lid (local id) of point by it&#39;s IESS</span></div>
<div class="line">    <span class="keywordtype">int</span> lid = client-&gt;<a class="code" href="classeds_1_1live_1_1_live_client.html#abcc332d091d41c17046a6fb6c0f5d117" title="Returns local id of point identified by IESS.">findByIESS</a>(pointName);</div>
<div class="line">    <span class="keywordflow">if</span> (lid == -1)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;Couldn&#39;t find point with IESS &#39;%s&#39;\n&quot;</span>, pointName);</div>
<div class="line">      <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    client-&gt;<a name="a6"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a4faa3daaa17de6d00f0cc637227a55f6" title="Registers LiveClient as a source of values for given point.">setOutput</a>(lid);</div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to originate point &#39;%s&#39; (%s)\n&quot;</span>, pointName, exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> downloadPointValues(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    <span class="keywordflow">do</span></div>
<div class="line">    {</div>
<div class="line">      client-&gt;<a name="a7"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a1c08a84afcc1ee39d7e8f2f37b0590ef" title="Receives updated point values from server.">synchronizeInput</a>();</div>
<div class="line">    } <span class="keywordflow">while</span> (client-&gt;<a name="a8"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#aa15606d8c4be4cd21926539a783beac2" title="Checks if LiveClient&#39;s point list requires an update.">isUpdateRequired</a>());</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to synchronize input point values (%s)\n&quot;</span>, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> printPointValues(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client, <span class="keyword">const</span> <span class="keywordtype">char</span>* pointName)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    <span class="keywordtype">int</span> lid = client-&gt;<a class="code" href="classeds_1_1live_1_1_live_client.html#abcc332d091d41c17046a6fb6c0f5d117" title="Returns local id of point identified by IESS.">findByIESS</a>(pointName);</div>
<div class="line">    <span class="keywordflow">if</span> (lid == -1)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;Couldn&#39;t find point with IESS &#39;%s&#39;\n&quot;</span>, pointName);</div>
<div class="line">      <span class="keywordflow">return</span>;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Read value of analog point</span></div>
<div class="line">    <span class="keywordtype">char</span> quality;</div>
<div class="line">    <span class="keywordtype">float</span> value = client-&gt;<a name="a9"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a7cf319635b45c401c4f6240ffad7dd9c" title="Reads analog process point value.">readAnalog</a>(lid, &amp;quality);</div>
<div class="line">    printf(<span class="stringliteral">&quot;lid=%d value=%f%c\n&quot;</span>, lid, value, quality);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Read string field by name</span></div>
<div class="line">    std::string iess = client-&gt;<a name="a10"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#ad3d4ca1de9c9858c85b1eab309236615" title="Reads string field value.">readFieldString</a>(lid, <span class="stringliteral">&quot;IESS&quot;</span>);</div>
<div class="line">    printf(<span class="stringliteral">&quot;lid=%d IESS=%s\n&quot;</span>, lid, iess.c_str());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Read string field by id</span></div>
<div class="line">    <span class="keywordtype">int</span> unFieldId = client-&gt;<a name="a11"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a151a07d62f45f6228580f9f98a9be91c" title="Returns identifier of point&#39;s field with specified name.">fieldIdFromName</a>(<span class="stringliteral">&quot;UN&quot;</span>);</div>
<div class="line">    std::string un = client-&gt;<a class="code" href="classeds_1_1live_1_1_live_client.html#ad3d4ca1de9c9858c85b1eab309236615" title="Reads string field value.">readFieldString</a>(lid, unFieldId);</div>
<div class="line">    printf(<span class="stringliteral">&quot;lid=%d UN=%s\n&quot;</span>, lid, un.c_str());</div>
<div class="line"></div>
<div class="line">    std::string t = client-&gt;<a class="code" href="classeds_1_1live_1_1_live_client.html#ad3d4ca1de9c9858c85b1eab309236615" title="Reads string field value.">readFieldString</a>(lid, <span class="stringliteral">&quot;T&quot;</span>);</div>
<div class="line">    printf(<span class="stringliteral">&quot;lid=%d T=%s\n&quot;</span>, lid, t.c_str());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Read double field</span></div>
<div class="line">    <span class="keywordtype">double</span> tb = client-&gt;<a name="a12"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a4496caf78cf74173efb064fdf8383f7b" title="Reads double field value.">readFieldDouble</a>(lid, <span class="stringliteral">&quot;TB&quot;</span>);</div>
<div class="line">    printf(<span class="stringliteral">&quot;lid=%d TB=%f\n&quot;</span>, lid, tb);</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to read values of point &#39;%s&#39; (%s)\n&quot;</span>,</div>
<div class="line">      pointName, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> uploadPointValues(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    client-&gt;<a name="a13"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#ad4419303b3afacf1503d06257f3a89f9" title="Sends updated point values to server.">synchronizeOutput</a>();</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to synchronize output point values (%s)\n&quot;</span>, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> writePoint(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client, <span class="keyword">const</span> <span class="keywordtype">char</span>* pointName, <span class="keywordtype">float</span> value)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    <span class="keywordtype">int</span> lid = client-&gt;<a class="code" href="classeds_1_1live_1_1_live_client.html#abcc332d091d41c17046a6fb6c0f5d117" title="Returns local id of point identified by IESS.">findByIESS</a>(pointName);</div>
<div class="line">    <span class="keywordflow">if</span> (lid == -1)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;Couldn&#39;t find point with IESS &#39;%s&#39;\n&quot;</span>, pointName);</div>
<div class="line">      <span class="keywordflow">return</span>;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    client-&gt;<a name="a14"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#aaba33c7cb740b83c248fba1ce7c9c88e" title="Writes analog value to process point.">write</a>(lid, value, eds::Quality_Good);</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to write values of point &#39;%s&#39; (%s)\n&quot;</span>,</div>
<div class="line">      pointName, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">if</span> (argc != 4)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Usage: %s version rhost rport\n&quot;</span>, argv[0]);</div>
<div class="line">    <span class="keywordflow">return</span> 1;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>* version = argv[1];</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>* rhost = argv[2];</div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> rport = (<span class="keywordtype">unsigned</span> short)atoi(argv[3]);</div>
<div class="line"></div>
<div class="line">  std::auto_ptr&lt;LiveClient&gt; client(initializeClient(version, rhost, rport));</div>
<div class="line">  <span class="keywordflow">if</span> (client.get() == 0)</div>
<div class="line">    <span class="keywordflow">return</span> 2;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Points have to be subscribed to receive value updates from server</span></div>
<div class="line">  <span class="keywordflow">if</span> (!subscribePoint(client.get(), <span class="stringliteral">&quot;A1&quot;</span>) ||</div>
<div class="line">      !subscribePoint(client.get(), <span class="stringliteral">&quot;A2&quot;</span>))</div>
<div class="line">    <span class="keywordflow">return</span> 3;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Points have to be originated to send value changes to server</span></div>
<div class="line">  <span class="keywordflow">if</span> (!originatePoint(client.get(), <span class="stringliteral">&quot;AOut&quot;</span>))</div>
<div class="line">    <span class="keywordflow">return</span> 4;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Read point values for 60 seconds</span></div>
<div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> t = 0; t &lt; 60; ++t)</div>
<div class="line">  {</div>
<div class="line">    downloadPointValues(client.get());</div>
<div class="line">    printf(<span class="stringliteral">&quot;------------------------------------------------\n&quot;</span>);</div>
<div class="line">    printPointValues(client.get(), <span class="stringliteral">&quot;A1&quot;</span>);</div>
<div class="line">    printPointValues(client.get(), <span class="stringliteral">&quot;A2&quot;</span>);</div>
<div class="line"></div>
<div class="line">    writePoint(client.get(), <span class="stringliteral">&quot;AOut&quot;</span>, utils::random&lt;float&gt;(0, 1));</div>
<div class="line">    uploadPointValues(client.get());</div>
<div class="line"></div>
<div class="line">    utils::sleep(1.0f);</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Tue Jul 31 2012 17:22:09 for EDS API by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.2 </li>
  </ul>
</div>
</body>
</html>
